/*
 * HttpRequest.h
 *
 *  Created on: Mar 14, 2012
 *      Author: shaohong
 */

#ifndef HTTPREQUEST_H_
#define HTTPREQUEST_H_

#include <string>
#include <vector>
#include <stdbool.h>
using namespace std;


//GET / HTTP/1.1
//User-Agent: nwprogClient 1.0
//Host: nwprog2.netlab.hut.fi
//Accept: */*

// data structure representing an HTTP request
// we'll only capture the most important information
class HttpRequest {
public:
	HttpRequest();
	virtual ~HttpRequest();

	string toString();

	bool isUsingProxy();

	string method;	//GET or PUT
	string requestUri;	// the request-uri of the http request
	vector<string> additionalHeaders;	// additional headers, e.g. Iam

	string userAgent;	//"nwprogClient 1.0" :)
	string hostHdrValue;	// the "Host" header value associated with this request
	string webProxyHost;	//proxy to be used, if set.
	int webProxyPort;
	/**
	 * return the value in the "content-length" header or -1 if the header doesn't exist.
	 */
	int getContentLength();


	// get the hostNName from request-uri
	string getHostNameInUrl();

	// get the port in the request-uri
	int getHostPortInUrl();

	// get the path in the request resource
	string getResourcePath();

	bool isGET();

	bool isPUT();

	/**
	 * get the header value from the "additional" headers
	 */
	string getHeaderValue(string headerName);
	string getHostInHostHeader();	// get the host from the Host header
	int getPortInHostHeader();	// get the port info from the Host header

	string getDomain(); // get the domain if the resource

	void removeHeader(string headerName);
	void addHeader(string headerName, string headerValue);
};

#endif /* HTTPREQUEST_H_ */
